package thread;

import java.util.concurrent.TimeUnit;

/**
 * \* User: Administrator
 * <p>
 * \* Date: 2020/10/28
 * <p>
 * \* Time: 13:35
 * <p>
 * \* Description:
 *  守护线程存在 不影响虚拟机退出
 * \
 */
public class DaemonThreadDemo {
    public static void main(String[] args) throws InterruptedException {
        long startTime = System.nanoTime();
        Thread t = new Thread(() -> {
            try {
                TimeUnit.DAYS.sleep(Long.MAX_VALUE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "Daemon-T");

        t.setDaemon(true);
        t.start();
        TimeUnit.SECONDS.sleep(15);

        System.out.println("系统退出，程序执行" + TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime) + " s");
    }
}
